package com.hancheng.commoncloud.framework.util;

import com.hancheng.commoncloud.business.entity.vo.SysUserVO;
import com.hancheng.commoncloud.framework.result.exception.ResultCode;
import lombok.extern.slf4j.Slf4j;


@Slf4j
public class LocalUserInfoUtil {
    private static ThreadLocal<SysUserVO> LOCAL_USER_INFO = new ThreadLocal();

    /**
     * 获取会员信息
     */
    public static SysUserVO getAdminUserPO() {
        SysUserVO sysUserVO = LOCAL_USER_INFO.get();
        ApiAssert.isNotNull(sysUserVO, ResultCode.USER_NOT_LOGGED_IN, "用户信息不存在，请重新登录");
        return sysUserVO;
    }

    /**
     * 移除防止内存溢出
     */
    public static void remove() {
        LOCAL_USER_INFO.remove();
    }

    /**
     * 设置
     *
     * @param sysUserVO
     */
    public static void set(SysUserVO sysUserVO) {
        LOCAL_USER_INFO.set(sysUserVO);
    }

}
